package niumao.minecraft.uhc.commands;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SetPVP implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (!player.isOp()) {
                player.sendMessage("Only Op can execute this command!");
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("setPVP")) {
                if (args.length == 2) {
                    String name = args[0];
                    boolean flag = true;
                    if (args[1].equalsIgnoreCase("false"))
                        flag = false;
                    World world = Bukkit.getWorld(name);
                    if (world == null) {
                        player.sendMessage("Cannot found this world.");
                        return true;
                    }
                    world.setPVP(flag);
                    player.sendMessage(ChatColor.GREEN + world.getName() + ChatColor.WHITE + " :PVP turn to " +ChatColor.GOLD +flag);
                    return true;
                }
                return false;
            }
        }
        sender.sendMessage(ChatColor.RED + "only Player can executor this command!");
        return true;
    }
}
